<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld"  prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld"  prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tlds/custom-html.tld" prefix="chtml" %>

<%@ page  import="java.util.ArrayList" %>

<%@ page  import="com.erp.framework.util.CommonUtil" %>
<%@ page  import="com.erp.app.common.ProjectConstants" %>
<%@ page  import="com.erp.app.admin.systemMenu.beans.SystemMenuGroupVO" %>
<%@ page  import="com.erp.app.util.web.WebUtil" %>
<%@ page  import="com.erp.framework.util.logger.Logger" %>

<%@ include file="/jsp/com/erp/app/common/jsp/html_include.jsp"%>

<jsp:useBean id="systemMenuSearchForm" scope="session" type="com.erp.app.admin.systemMenu.web.SystemMenuSearchForm" />

<script language="javascript">
function doEdit(val, val2, val3) {
    document.forms[0].editCompanyCode.value = val;
		document.forms[0].editGroupId.value = val2;
		document.forms[0].editMenuId.value = val3;
    doSubmit('edit');
}

function doLoad() {
	<%
	if (CommonUtil.nullToString((String)session.getAttribute(ProjectConstants.SESSION_ALERT_AFTER_DELETE)).equals(ProjectConstants.GENERIC_YES)) {
		session.removeAttribute(ProjectConstants.SESSION_ALERT_AFTER_DELETE);
		out.println("alert('Record deleted.');");
	}
	%>
}

var isSubmitted = 0;
function doSubmit(event, val) {
	if (isSubmitted == 0) {
		isSubmitted = 1;
		document.forms[0].pageEvent.value = event;
		if (val != null) {
			document.forms[0].pageEventSrc.value = val;
		}
		document.forms[0].submit();
	}
}
</script>

<body onLoad="javascript:doLoad();autofill_init();">

<html:form action="/systemMenuSearch">
<html:hidden property="pageEvent" />
<html:hidden property="pageMode" />
<html:hidden property="editCompanyCode" />
<html:hidden property="editGroupId" />
<html:hidden property="editMenuId" />

<!-- Search Criteria -->

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
    <td>
	<chtml:button form="systemMenuSearchForm" pageEvent="exit" styleClass="button1" />
	<chtml:button form="systemMenuSearchForm" pageEvent="search" styleClass="button1" />
<%--
	<chtml:button form="systemMenuSearchForm" pageEvent="create" styleClass="button1" />
--%>
	<chtml:button form="systemMenuSearchForm" pageEvent="clear" styleClass="button1" />
    </td>
</tr>
<tr>  
    <td>

    <table bordercolor=#808080 cellspacing=1 cellpadding=2 width=660 border=0 bgcolor="#C1C1C1">
			<tr bgcolor="#637ACB" class="t2"> 
				<td valign=top width=150 class="col_label">&nbsp</td>
				<td valign=top width=200 class="col_label">&nbsp</td>
			</tr>
			<tr valign=top class="col_label"> 
				<td width=150>Menu Name</td>
				<td width=200 class="col_value">
				    <html:text property="srchMenuName" size="20" maxlength="30" styleClass="t2" />
				</td>
			</tr>
<%
String menuType = systemMenuSearchForm.getSrchMenuType();
String menuSelected = "";
String itemSelected = "";

if(ProjectConstants.MENU_TYPE_MENU.equalsIgnoreCase(menuType)){
	menuSelected = "selected";
} else if(ProjectConstants.MENU_TYPE_ITEM.equalsIgnoreCase(menuType)){
	itemSelected = "selected";
}
%>
			<tr valign=top class="col_label"> 
				<td width=150>Menu Type</td>
				<td width=200 class="col_value">
					<select name="srchMenuType" class="t2">
						<option value=""></option>
						<option value="<%=ProjectConstants.MENU_TYPE_MENU%>" <%=menuSelected%>>Menu</option>
						<option value="<%=ProjectConstants.MENU_TYPE_ITEM%>" <%=itemSelected%>>Item</option>
					</select>
				</td>
			</tr>
			<tr valign=top class="col_label"> 
				<td width=150>Parent Menu Name</td>
				<td width=200 class="col_value">
					<% 
						where = "COMPANY_CODE = '" + WebUtil.getAppropriateCompanyCode(session, null) + "'";
						where += " AND MENU_TYPE='M'"; 
						String selected = "";
						String parentMenuId = systemMenuSearchForm.getSrchParentMenuId();
						if(ProjectConstants.PARENT_MENU_ALERT_LIST.equals(parentMenuId)){
							selected = "selected";
						} else if(ProjectConstants.PARENT_MENU_TODO_LIST.equals(parentMenuId)){
							selected = "selected";
						}						
					%>
					<select name="srchParentMenuId" class="t2">
						<option value=""></option>
						<option value="<%=ProjectConstants.PARENT_MENU_ALERT_LIST%>" <%=selected%>><%=ProjectConstants.PARENT_MENU_ALERT_LIST%></option>						
						<option value="<%=ProjectConstants.PARENT_MENU_TODO_LIST%>" <%=selected%>><%=ProjectConstants.PARENT_MENU_TODO_LIST%></option>	
						<chtml:options table="T_MENU_GROUP"
									valuecolumn="MENU_ID"
									textcolumn="MENU_NAME"
									order="MENU_NAME" 
									where="<%=where%>"
									selected="<%= systemMenuSearchForm.getSrchParentMenuId() %>" />
					</select>
				</td>
			</tr>
			<tr valign=top class="col_label">
				<td width=150>Group ID</td>
				<td width=200 class="col_value">
					<%--<select name="srchGroupId" class="t2">
					<% String where2 = "COMPANY_CODE  = '" + WebUtil.getAppropriateCompanyCode(session, WebUtil.getCodeSysParamId(ProjectConstants.CD_MENU_GROUP)) + "'";
						where2 += " AND REF_MASTER_CODE ='" + ProjectConstants.CD_MENU_GROUP + "' AND REF_STATUS = '"+ProjectConstants.GENERIC_ACTIVE+"' ";%>
					<chtml:options table="T_CODE_DTL"
								valuecolumn="REF_CODE"
								textcolumn="REF_CODE"
								where= "<%=where2%>"
								order="REF_CODE"
								selected="<%=systemMenuSearchForm.getSrchGroupId()%>" />
					</select>--%>
				<%ArrayList groupIdCollection = systemMenuSearchForm.getCodeDtlDropdownCollection(WebUtil.getAppropriateCompanyCode(session, WebUtil.getCodeSysParamId(ProjectConstants.CD_MENU_GROUP)), 
                                                                                      ProjectConstants.CD_MENU_GROUP, 
                                                                                      systemMenuSearchForm.getSrchGroupId(), 
                                                                                      true); 
					pageContext.setAttribute("groupIdCollection",  groupIdCollection); %> 
				<html:select property  = "srchGroupId" styleClass =  "t2"> 
					<html:option  value = ""></html:option> 
			        <html:options  collection = "groupIdCollection" 
								labelProperty = "dtlRefDesc" 
									 property = "refCode"/> 
				</html:select> 

				</td>
			</tr>
			<%if(Logger.getLogLevel() > Logger.LOG_LEVEL_DEBUG) { %>
			<tr valign=top class="col_label">
				<td width=150>Status</td>
				<td width=200 class="col_value">
					<select name="srchStatus" class="selectBox1">
						<%where = " TYPE = '" +  ProjectConstants.CONSTANT_TYPE_ACT_INACT + "' ";%>
						<option value="">
						<chtml:options table="T_SYS_CONSTANTS"
						valuecolumn="CONSTANT_CODE"
						textcolumn="CONSTANT_NAME"
						where= "<%=where%>"
						order="CONSTANT_NAME"
						selected="<%=systemMenuSearchForm.getSrchStatus()%>"
						 />
					</select>
				</td>
			</tr>
			<% } %>
    </table>	
    
	</td>
</tr>
<tr>
	<td><font color='red'><html:errors /></font></td>
</tr>





<!-- ***** Listing Search Results ***** -->

<tr>
	<td class="t2" align="right" colspan="2">
	<% if (systemMenuSearchForm.getTotalPage() == 0) { %>
		&nbsp;
	<% } else { %>
		Page <%=systemMenuSearchForm.getCurrentPage()%> of <%=systemMenuSearchForm.getTotalPage()%>
	<% } %>
	
		<input type="button" value="&lt;&lt;" class="t2" onClick="javascript:doSubmit('scrollLeft');" <%=systemMenuSearchForm.getSidx() == 0 ? "disabled" : ""%>>
		<input type="button" value="&gt;&gt;" class="t2" onClick="javascript:doSubmit('scrollRight');" <%=systemMenuSearchForm.getSidx() < Integer.parseInt(systemMenuSearchForm.getLastPageSidx()) ? "" : "disabled"%>>
	</td>
</tr>
</table>
<table width="100%" cellspacing="1" cellpadding="1">
<tr align="center"> 
	<td class="grid_header">Menu Name</td>
	<td class="grid_header">Menu ID</td>
	<td class="grid_header">Group ID</td>
	<td class="grid_header">Menu Type</td>
	<td class="grid_header">Parent Menu ID</td>
	<td class="grid_header">Menu Order</td>
</tr>

<logic:iterate id="srchRsltRow" name="systemMenuSearchForm" property="resultList" indexId="idx" length="<%=String.valueOf(ProjectConstants.MAX_DISPLAY)%>" offset="<%=String.valueOf(systemMenuSearchForm.getSidx())%>">
<%
    SystemMenuGroupVO vo = (SystemMenuGroupVO) srchRsltRow;
	String gridStyle = (idx.intValue()%2 == 0) ? "grid_result1" : "grid_result2";
%>

<tr class="<%=gridStyle%>" 
	onmouseover="mouseOverHighlight(event,'grid_row_action_hilite')"
	onmouseout="mouseOutHighlight('<%=gridStyle%>')"
	onclick="javascript:doEdit('<%=vo.getCompanyCode()%>', '<%=vo.getGroupId()%>', '<%=vo.getMenuId()%>')">
    <td class="grid_outline">		
		<bean:write name="srchRsltRow" property="menuName"/>
	</td>
	<td class="grid_outline">
		<bean:write name="srchRsltRow" property="menuId"/>
	</td>
	<td class="grid_outline">
		<bean:write name="srchRsltRow" property="groupId"/>
	</td>
	<td class="grid_outline">
		<%	
		if (!CommonUtil.nullToString(vo.getMenuType()).equals("")) {
			out.print(vo.getMenuType().equals("W") ? "Item" : "Menu");
		} else {
			out.print("N/A");
		}
		%>
	</td>
	<td class="grid_outline">
		<bean:write name="srchRsltRow" property="parentMenuId"/>
	</td>
	<td class="grid_outline">
		<bean:write name="srchRsltRow" property="menuOrder"/>
	</td>
</tr>
</logic:iterate>
</table>

</html:form>
